package com.xbongbong.saas.model;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.wrap.IModel;
import com.xbongbong.pro.businessdata.pojo.dto.FormatExplainDTO;
import com.xbongbong.pro.domain.entity.UpdateDataEntity;
import com.xbongbong.pro.formdata.pojo.dto.SaasAnalysisDataDTO;
import com.xbongbong.pro.purchaseinvoice.dto.PurchaseInvoiceAmountDetailGetDTO;
import com.xbongbong.pro.purchaseinvoice.vo.PurchaseInvoiceAmountDetailVO;
import com.xbongbong.saas.domain.entity.ext.PurchaseInvoiceEntityExt;
import org.elasticsearch.action.support.WriteRequest;

import java.util.List;
import java.util.Map;

/**
 * @author yuqian
 * @version v1.0
 * @date 2020/2/17 17:23
 * @since v1.0
 */
public interface PurchaseInvoiceModel extends IModel<PurchaseInvoiceEntityExt> {

    /**
     * 保存实体
     *
     * @param invoiceEntity 发票实体
     * @return java.lang.Integer
     * @throws XbbException 数据库异常
     * @author yuqian
     * @date 2019/2/14 16:42
     */
    Integer save(PurchaseInvoiceEntityExt invoiceEntity) throws XbbException;

    /**
     * 获取单个实体
     *
     * @param key    id主键
     * @param corpid 公司id
     * @return com.xbongbong.saas.domain.entity.PurchaseInvoiceEntityExt
     * @author feng.zheng
     * @date 2019/2/14 16:43
     */
    PurchaseInvoiceEntityExt getByKey(Long key, String corpid);


    /**
     * 批量更新
     * @param valueList 数据列表
     * @param idsList id列表
     * @param corpid 公司id
     * @throws XbbException
     * @return
     */
    Integer updateBatchByRule(List<Map<String, Object>> valueList, List<Long> idsList, String corpid) throws XbbException;


    /**
     * 批量删除
     * @param idIn 数据id列表
     * @param corpid 公司id
     * @return
     * @throws XbbException
     */
    Integer deleteBatch(List<Long> idIn, String corpid) throws XbbException;

    /**
     * 单个删除
     * @param id
     * @param corpid
     * @return
     * @throws XbbException
     */
    Integer deleteByKey(Long id,String corpid) throws XbbException;

    /**
     * 批量编辑
     * @author yuqian
     * @date 2019/3/20 15:40
     * @param updateList
     * @param corpid 公司id
     * @return java.lang.Integer
     * @throws XbbException 业务异常
     */
    Integer updateBatch(List<UpdateDataEntity> updateList, String corpid) throws XbbException;

    Integer updateBatch(List<UpdateDataEntity> updateList, String corpid, WriteRequest.RefreshPolicy refreshPolicy) throws XbbException;

    @Deprecated
    Integer updateBatch(List<UpdateDataEntity> updateList, String corpid,boolean needThrow) throws XbbException;

    /**
     * 获取符合查询条件的记录
     *
     * @param param 查询条件
     * @return 符合查询条件的记录
     */
    @Override
    List<PurchaseInvoiceEntityExt> findEntitys(Map<String, Object> param);


    /**
     * 根据合同id 和 付款计划id 或付款单id 查询发票
     * @param param
     * @return
     */
    List<PurchaseInvoiceEntityExt> getEntityByPurchaseIdOrRefId(Map<String,Object> param);


    List<PurchaseInvoiceEntityExt> getRedPurchaseInvoice(Map<String,Object> param);

    /**
     * 数据还原
     * @author xingxing.xiao
     */
    Integer restoreBatch(List<Long> dataIdList, String corpid, Integer del) throws XbbException;

    List<PurchaseInvoiceEntityExt> findEntitysWithoutSub(Map<String, Object> param);

    /**
     * 获取红冲总金额
     *
     * @param originId 原始id
     * @param corpid   公司id
     * @return double
     * @throws XbbException 异常
     */
    Double getRedTotalMoney(Long originId, String corpid) throws XbbException;

    /**
     * 编辑时改变解释
     *
     * @param formatExplainDTO 入参
     * @throws XbbException 异常
     */
    void formatUpdateExplain(FormatExplainDTO formatExplainDTO) throws XbbException;

    /**
     * 编辑时将获取数据格式化
     *
     * @param formDataUpdateGetDTO saas编辑数据
     * @param result               要返回的jsonobject
     * @throws XbbException 业务异常
     * @author feng.zheng
     * @date 2019/1/22 15:28
     */
    void formatData(SaasAnalysisDataDTO formDataUpdateGetDTO, JSONObject result) throws XbbException;

    PurchaseInvoiceAmountDetailVO getPurchaseInvoiceAmountDetail(PurchaseInvoiceAmountDetailGetDTO purchaseInvoiceAmountDetailGetDTO) throws XbbException;

    JSONArray approveGetAmountDetail(String corpid, Integer businessType, JSONObject data, Long dataId, String saasNeedPoJo) throws XbbException;
}
